package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.entity.Dish;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.lang.annotation.ElementType;
import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 查询购物车内物品
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新购物车，number+1
     * @param shoppingCart
     */
    void update(ShoppingCart shoppingCart);

    /**
     * 将物品放入购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void addCart(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id=#{id}")
    void clean(Long currentId);

    /**
     * num-1
     * @param shoppingCart
     */
    void updateOne(ShoppingCart shoppingCart);

    /**
     * 若num=0，删除物品
     * @param id
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void delete(Long id);

    /**
     * 根据id查询购物车内物品
     * @param id
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{id}")
    List<ShoppingCart> selectById(Long id);

    /**
     * 批量插入
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
